import React, {Component, Fragment} from 'react';
import {inject, observer} from 'mobx-react';
import {toJS} from "mobx";
import {
    WeaLocaleProvider,
    WeaTab,
    WeaTop,
    WeaDialog,
    WeaNewScroll,
    WeaRightMenu,
} from "ecCom";
import {WeaTableNew} from "comsMobx";
import {Button} from "antd";
import NoRightComponent from '../NoRightComponent.js';
import * as IconConstant from '../../constant/IconConstant.js';
import LanguageConstant from '../../constant/LanguageConstant';
import * as Constant from '../../constant/Constant';

const {getLabel} = WeaLocaleProvider;
const {WeaTable} = WeaTableNew;

@inject("initConfigListStore")
@observer
class InitConfigListPage extends Component {

    componentDidMount() {
        const {initConfigListStore} = this.props;
        initConfigListStore.getTableData();
    }

    render() {
        const {initConfigListStore} = this.props;
        const {tableStore, authorized, loading} = initConfigListStore;
        if (!authorized) {
            return (<NoRightComponent/>);
        }
        return (
            <div className="init-config-list">
                <WeaRightMenu datas={this.getDropMenuDatas()}>
                    <WeaTop
                        title={getLabel(LanguageConstant.APPLICATION_SETTING, "应用设置")}
                        icon={<i className={IconConstant.WEATOP_ICON}/>}
                        iconBgcolor={IconConstant.WEATOP_ICON_BG_COLOR}
                        buttons={this.getWeaTop()}
                        loading={loading}
                        showDropIcon={true}
                        dropMenuDatas={this.getDropMenuDatas()}
                    >
                        <Fragment>
                            <WeaTable
                                hasOrder={true}
                                needScroll={true}
                                comsWeaTableStore={tableStore}
                            />
                        </Fragment>
                    </WeaTop>
                </WeaRightMenu>
            </div>
        );
    }

    getDropMenuDatas = () => {
        const {initConfigListStore} = this.props;
        const {loading, affirmInitAll} = initConfigListStore;
        const dropMenuDatas = [
            {
                key: '1',
                disabled: loading,
                icon: <i className='icon-coms-Add-to'/>,
                content: getLabel(LanguageConstant.ONE_KEY_INIT, "一键初始化"),
                onClick: key => affirmInitAll(),
            }
        ];
        return dropMenuDatas;
    }

    getWeaTop = () => {
        const {initConfigListStore} = this.props;
        const {loading, affirmInitAll} = initConfigListStore;
        const btns = [
            <Button type="primary"
                    onClick={() => affirmInitAll()}>{getLabel(LanguageConstant.ONE_KEY_INIT, "一键初始化")}</Button>,
        ]
        return btns;
    }


}

export default InitConfigListPage;
